package com.service.transaction;

import java.sql.Connection;
import java.sql.Savepoint;

/**
 * Created with IntelliJ IDEA.
 * User: Georgiana.Scarlat
 * Date: 8/1/12
 * Time: 10:45 AM
 */
public class Transaction {
    private Savepoint savepoint;
    private boolean previousAutoCommitState;
    private String name;

    public Transaction(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Transaction{" +
                "name='" + name + '\'' +
                '}';
    }

    private Connection connection;

    public Savepoint getSavepoint() {
        return savepoint;
    }

    public void setSavepoint(Savepoint savepoint) {
        this.savepoint = savepoint;
    }

    public boolean getPreviousAutoCommitState() {
        return previousAutoCommitState;
    }

    public void setPreviousAutoCommitState(boolean previousAutoCommitState) {
        this.previousAutoCommitState = previousAutoCommitState;
    }

    public Connection getConnection() {
        return connection;
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public String getName() {
        return name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Transaction that = (Transaction) o;

        return previousAutoCommitState == that.previousAutoCommitState && !(connection != null ? !connection.equals(that.connection) : that.connection != null) && !(name != null ? !name.equals(that.name) : that.name != null) && !(savepoint != null ? !savepoint.equals(that.savepoint) : that.savepoint != null);

    }

    @Override
    public int hashCode() {
        int result = savepoint != null ? savepoint.hashCode() : 0;
        result = 31 * result + (previousAutoCommitState ? 1 : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (connection != null ? connection.hashCode() : 0);
        return result;
    }
}
